package com.example.lx5_22

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.ToastUtils
import com.example.base.mvvm.BaseActivity
import com.example.lx5_22.databinding.ActivityQueryParkBinding
import com.example.lx5_22.park.ParkViewModel
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/QueryParkActivity")
class QueryParkActivity : BaseActivity<ActivityQueryParkBinding,ParkViewModel>() {

    @Autowired
    @JvmField
    var parkId = 0

    @Autowired
    @JvmField
    var status = ""
    override fun initView() {
        ARouter.getInstance().inject(this)

        binding.tv.text = parkId.toString()

        if(status == "空闲"){
            binding.rbFree.isChecked = true
        }else if(status == "已占用"){
            binding.rbOccupied.isChecked = true
        }else if(status == "维护中"){
            binding.rbMaintenance.isChecked = true
        }

        binding.rgParkingStatus.setOnCheckedChangeListener { radioGroup, i ->
            when(i){
                R.id.rbFree ->
                    status = "空闲"
                R.id.rbOccupied ->
                    status = "已占用"
                R.id.rbMaintenance ->
                    status = "维护中"
            }
        }

        binding.ivYes.setOnClickListener {
            viewModel.getQueryParkData(parkId,status)
        }

        println("111")

    }

    override fun initData() {
        viewModel.queryParkData.observe(this){
            ToastUtils.showLong("修改成功")
            finish()
        }
    }

}